package com.jiangyg.mall.core.support.restful;

import com.jiangyg.mall.core.enums.Operator;
import com.jiangyg.mall.core.support.validation.constraints.AlphanumericUnderline;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 类描述：查询条件
 * 
 * @author jiangyg
 * @date 2020-02-25
 * @version 2.0
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode
public class Criteria implements Serializable {

    private static final long serialVersionUID = -5812563367714568764L;

    /**
     * 查询条件字段名
     */
    @AlphanumericUnderline
    private String name;

    /**
     * 操作符：eq、gt、ge、lt、le、lk、ll、rl和bt
     * <p>
     * 当运算符为eq、gt、ge、lt、le、lk、ll、rl时，值为value
     * <p>
     * 当运算符为bt时，值为values
     */
    private String operator = Operator.LL.code;

    /**
     * 查询条件的值
     */
    // TODO xss 判断，防止SQL注入
    private Object value;

    /**
     * 查询条件的值
     */
    // TODO xss 判断，防止SQL注入
    private Object[] values;

    public Criteria(@AlphanumericUnderline String name, String operator, Object value) {
        this.name = name;
        this.operator = operator;
        this.value = value;
    }

    public Criteria(@AlphanumericUnderline String name, String operator, Object[] values) {
        this.name = name;
        this.operator = operator;
        this.values = values;
    }

}
